package com.k.sshm.boot.extra.squirrel.order.controller;

import com.k.sshm.boot.extra.squirrel.order.conf.OrderContext;
import com.k.sshm.boot.extra.squirrel.order.conf.OrderDTO;
import com.k.sshm.boot.extra.squirrel.order.conf.OrderEvent;
import com.k.sshm.boot.extra.squirrel.order.conf.OrderState;
import com.k.sshm.boot.extra.squirrel.order.mast.OrderStateMachineEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/order/")
public class OrderController {

    // 注入状态机
    @Autowired
    OrderStateMachineEngine orderStateMachineEngine;


    @RequestMapping("/create")
    public void create() {
        OrderDTO orderDTO = new OrderDTO();
        orderDTO.setState(OrderState.INIT);
        OrderContext orderContext = new OrderContext();
        orderContext.setOrderDTO(orderDTO);
        orderStateMachineEngine.fire(OrderEvent.CREATE_ORDER, orderContext);
    }

    @RequestMapping("/test")
    public void test() {
        OrderDTO orderDTO = new OrderDTO();
        orderDTO.setState(OrderState.INIT);
        OrderContext orderContext = new OrderContext();
        orderContext.setOrderDTO(orderDTO);
        orderStateMachineEngine.fire(OrderEvent.SUBMIT_ORDER, orderContext);
    }

}